package controller;

import model.Product;
import java.util.ArrayList;
import java.util.List;

public class ProductController {
    private List<Product> productList = new ArrayList<>();

    public void addProduct(Product product) {
        productList.add(product);
    }

    public Product getProduct(int id) {
        return productList.stream().filter(p -> p.getId() == id).findFirst().orElse(null);
    }

    public void updateProduct(Product product) {
        for (int i = 0; i < productList.size(); i++) {
            if (productList.get(i).getId() == product.getId()) {
                productList.set(i, product);
                break;
            }
        }
    }

    public void deleteProduct(int id) {
        productList.removeIf(p -> p.getId() == id);
    }

    public List<Product> getAllProducts() {
        return productList;
    }
}